package cn.itcast.web.exception;

import org.apache.shiro.authz.UnauthorizedException;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 自定义异常处理器
 */
public class SaaSException implements HandlerExceptionResolver {
 @Override
 public ModelAndView resolveException(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) {

  if (e instanceof UnauthorizedException) {
   ModelAndView ma = new ModelAndView();
   ma.setViewName("forward:unauthorized.jsp");
   return ma;
  }
  ModelAndView ma = new ModelAndView();
  ma.setViewName("error");
  ma.addObject("errorMsg", e.getMessage());
  e.printStackTrace();
  return ma;
 }
}
